package com.njbw.minio.entity;

import io.minio.messages.Owner;
import io.minio.messages.Part;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.Root;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

@Root(name = "ListPartsResult", strict = false)
@Namespace(reference = "http://s3.amazonaws.com/doc/2006-03-01/")
public class CustomListPartsResult {
    @Element(name = "Bucket")
    private String bucketName;

    @Element(name = "Key")
    private String objectName;

    @Element(name = "Initiator")
    private CustomInitiator initiator;

    @Element(name = "Owner")
    private Owner owner;

    @Element(name = "StorageClass")
    private String storageClass;

    @Element(name = "PartNumberMarker")
    private int partNumberMarker;

    @Element(name = "NextPartNumberMarker")
    private int nextPartNumberMarker;

    @Element(name = "MaxParts")
    private int maxParts;

    @Element(name = "IsTruncated")
    private boolean isTruncated;

    @ElementList(name = "Part", inline = true, required = false)
    private List<Part> partList;

    public CustomListPartsResult() {
    }

    /**
     * Returns bucket name.
     */
    public String bucketName() {
        return bucketName;
    }

    /**
     * Returns object name.
     */
    public String objectName() {
        return objectName;
    }

    /**
     * Returns storage class.
     */
    public String storageClass() {
        return storageClass;
    }

    /**
     * Returns initator information.
     */
    public CustomInitiator initiator() {
        return initiator;
    }

    /**
     * Returns owner information.
     */
    public Owner owner() {
        return owner;
    }

    /**
     * Returns maximum parts information received.
     */
    public int maxParts() {
        return maxParts;
    }

    /**
     * Returns whether the result is truncated or not.
     */
    public boolean isTruncated() {
        return isTruncated;
    }

    /**
     * Returns part number marker.
     */
    public int partNumberMarker() {
        return partNumberMarker;
    }

    /**
     * Returns next part number marker.
     */
    public int nextPartNumberMarker() {
        return nextPartNumberMarker;
    }

    /**
     * Returns List of Part.
     */
    public List<Part> partList() {
        if (partList == null) {
            return Collections.unmodifiableList(new LinkedList<>());
        }

        return Collections.unmodifiableList(partList);
    }
}
